< previous page page_276 next page >

Page 276
0276-01.jpg
Figure 8.3.
Using the 
SELECT_FROM statement to change column display order.
The ORDER BY Clause
When you use the SELECT_FROM statement, the records returned in the result set are returned in the order in which they were found in the underlying table. But what if you wanted to display the results of your SELECT_FROM statement in a specialized sorted order? You can use the ORDER BY clause to do just that.
Placing ASC or DESC after each field in the ORDER BY clause indicates the order in which you want to sort the column, ascending or descending. If no order is supplied, SQL assumes that you want the set sorted in ascending order.
The following SQL example shows how you can display the records in the Authors table in descending sorted order, by Author Name.
SELECT * FROM AUTHORS ORDER BY Name DESC
Enter this statement in the SQL window of Visdata and execute it. Compare your results to Figure 8.4.
You can enter more than one field in the ORDER BY clause. SQL will create a result set that reflects the aggregate sort of the ORDER BY clause. Using Visual Basic Visdata, enter and execute the following SELECT_FROM statement. Compare your results to those in Figure 8.5.
SELECT StateProv, City FROM Publishers ORDER BY StateProv DESC, City ASC
Notice in the example shown in Figure 8.5 that you have combined the ability to alter the row order of the data in the result set with the ability to alter the column order of the data in the result set. These are powerful tools. Now that you know how to use SQL to display complete, single-data tables, you can learn how to limit the result set to only those records you need.

 
< previous page page_276 next page >

If you like this book, buy it!